/**
 * Created by 小敏哥 on 2017/3/23.
 */
import React, {Component} from 'react';
import style from './homePageHeader.scss';
import ButtonWithCxytj from '../common/buttonWithCxytj';
import ReModal from '../../components/common/reModal';
import typeOfBrowser from '../../utils/typeOfBrowser';

class HomePageHeader extends Component {
    constructor(props) {
        super(props);
    }

    goToQuestion() {
        //history.replaceState({},'','#/questions');
        this.context.router.push('/questions');
    }

    showConfirmDialog() {
        //兼容qq浏览器ios版本不支持tel协议
        if(navigator.userAgent.indexOf('iPhone')>-1&&localStorage.getItem('detailUserType').indexOf('QQ')>-1) {
            ReModal.alert('客服热线：020-62936789');
        }
        else {
            window.location.href = "tel:020-62936789";
        }
    }

    //跳转到订单列表
    goToOrderList(){
        this.context.router.push('/orderList');
    }

    //根据不同的渠道渲染不同的右侧按钮
    renderRightButton(){
        let userType=sessionStorage.getItem('userType');
        //京东：jindong2016，淘宝我的爱车：SJTB2017，天猫：CXYTMALL等非自有渠道，显示订单列表
        if (userType == 'jindongns2016' || userType == 'SJTB2017' || userType == 'CXYTMALL') {
            return <ButtonWithCxytj  onClick={()=>{this.goToOrderList()}}>订单列表</ButtonWithCxytj>
        }
        else{
            return <ButtonWithCxytj countOption={{
                eventId: 'H5_E_Interspection_Homepage_ClickCustomerService',
            }} onClick={this.showConfirmDialog}>联系客服</ButtonWithCxytj>
        }
    }

    /*    closeAll(){
     if(window.AlipayJSBridge){
     AlipayJSBridge.call('popWindow');
     }
     }*/

    render() {
        return <div className={style.container} onClick={this.closeAll}>
            <div className={style.mainTitle}>车辆年检代办服务</div>
            <div className={style.buttonGroup}>
                <ButtonWithCxytj countOption={{
                    eventId: 'H5_E_Interspection_Homepage_ClickCheackQA',
                }} onClick={()=>{this.goToQuestion()}}>常见问题(19)</ButtonWithCxytj>
                {this.renderRightButton()}
            </div>
        </div>
    }
}

//使用context
HomePageHeader.contextTypes = {
    router: React.PropTypes.object.isRequired
};

export default HomePageHeader